package com.wlyuan.open.scanner.domain.message;

import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author lijing
 * @description
 */
@Getter
public enum OperationTypeEnum {

    READ("r", 0),
    CREATE("c", 1),
    UPDATE("u", 2),
    DELETE("d", 3),
    TRUNCATE("t", 4);

    private String code;
    private Integer value;

    OperationTypeEnum(String code, Integer value) {
        this.code = code;
        this.value = value;
    }

    private static final Map<String, OperationTypeEnum> MAP = Arrays.asList(OperationTypeEnum.values()).stream().collect(Collectors.toMap(OperationTypeEnum::getCode, Function.identity()));

    public static OperationTypeEnum fromValue(String code) {
        return MAP.get(code);
    }

    public static boolean isCreate(String code) {
        return CREATE.getCode().equals(code);
    }

    public static boolean isUpdate(String code) {
        return UPDATE.getCode().equals(code);
    }

    public static boolean isDelete(String code) {
        return DELETE.getCode().equals(code);
    }

    public static boolean isRead(String code) {
        return READ.getCode().equals(code);
    }
}
